from flask import Blueprint, jsonify, request
import requests
import json
import logging
from app.utils.AESC import AESCrypto_Yzdyh
import time

gjbwg_bp = Blueprint('gjbwg', __name__, url_prefix='/gjbwg')


@gjbwg_bp.route('/todoTg', methods=['GET'])
def todoTg():
    url = f"https://wapticket.chnmuseum.cn/prod-api/basesetting/HallSetting/ingore/gainAllSystemConfig?channel=wxMini&requestTaskKey=gainAllSystemConfigLogin&ticketUseType=1&p=wxmini";
    # 发送网络请求
    headers = {}
    try:
        # 发送GET请求
        response = requests.get(url, headers=headers)
        # 检查响应状态
        if response.status_code == 200:
            print(f"body={response.text}")
            return jsonify({
                "status": "success",
                "data": response.json()  # 假设返回的是 JSON
            })
        else:
            print(f"请求失败，状态码: {response.status_code}")
            return jsonify({
                "status": "error",
                "code": response.status_code,
                "message": "API 请求失败"
            }), 400
    except Exception as e:
        print(f"请求发生异常: {str(e)}")
        return jsonify({
            "status": "error",
            "message": f"请求异常: {str(e)}"
        }), 500  # 返回 HTTP 500 状态码


@gjbwg_bp.route('/addOrder', methods=['GET'])
def addOrder():
    url = "https://wxmini.chnmuseum.cn/prod-api/config/orderRule/placeOrder";
    # 请求配置
    headers = {}
    params = {
        "useTicketType": 1,
        "poolFlag": 1,
        "realNameFlag": 1,
        "platform": 2,
        "ticketNum": 1,
        "date": "2025-05-20",
        "childTicketNum": 0,
        "saleMode": 1,
        "pointJson": "ULM4uyj6STUAg8lkFS+MECfuojHjqlrCfMACWkhMizU=",
        "captchaToken": "06e985da687c4cf9a202f5a93c33807e-24624649-1747649451031",
        "scanToken": "",
        "ticketInfoList": [
            {
                "status": 0,
                "saleMode": 1,
                "platform": 2,
                "hallId": 1,
                "hallScheduleId": 1,
                "cinemaFlag": 0,
                "ticketPriceId": 8,
                "certificate": 1,
                "certificateInfo": "622627199711264610",
                "userName": "何荣",
                "useDate": "2025-05-20 00:00:00",
                "isChildFreeTicket": 0,
                "realNameFlag": 1
            }
        ],
        "deviceToken": "v2:9akBLY98IqLmqZK5vD6SWC8EUWG/fnMHkd3JYSM+HeILBWzCkP/OYKiuqgSOR6CXn/RyY+uVnd6yDmjsea1vdbF+29C7+f6+O1peXI1SU0ls5Bbb6wbnm8l9r6gG7Ir5Ev3P0xrF+Iw8b6U/SyLAjNCESNaOZFdR5MBYR/RaqctDptfkJ4Jj3Kyp+1XLQRkAu3ZumKtTi5a2qe6QScPzjmnt52fV5kggLeMlwhAy1W45m4An3XpWWAgh+g4/aD7sVKJIPmeaxzEcka+BI+ZTqckIt6/9iRDqhaEPGxlIdpelcgc=",
        "p": "wxmini"
    }
    try:
        response = requests.post(
            url,
            headers=headers,
            data=json.dumps(params),
        );
        # 检查响应状态
        if response.status_code == 200:
            print(f"body={response.text}")
            return jsonify({
                "status": "success",
                "data": response.json()  # 假设返回的是 JSON
            })
        else:
            print(f"请求失败，状态码:{response.status_code} {response.text}")
            return jsonify({
                "status": "error",
                "code": response.status_code,
                "message": "API 请求失败"
            }), 400
    except Exception as e:
        print(f"请求发生异常: {str(e)}")
        return jsonify({
            "status": "error",
            "message": f"请求异常: {str(e)}"
        }),
